extends Node2D
tool

signal on_grid_click(gridName)

# TYPE

enum GRID_TYPE { CROSS, \
				 LEFT_TOP_CORNER, LEFT_BOTTOM_CORNER , RIGHT_TOP_CORNER,  RIGHT_BOTTOM_CORNER, \
				 TOP_CROSS, BOTTOM_CROSS, \
				 LEFT_CROSS, RIGHT_CROSS }

export(GRID_TYPE) var grid_type = GRID_TYPE.CROSS


# Called when the node enters the scene tree for the first time.
func _ready():
	var resName = "Board_cross"
	match grid_type:
		GRID_TYPE.CROSS:
			resName = "Board_cross"
		GRID_TYPE.LEFT_TOP_CORNER:
			resName = "Board_left_top_corner"
		GRID_TYPE.LEFT_BOTTOM_CORNER:
			resName = "Board_left_bottom_corner"
		GRID_TYPE.RIGHT_TOP_CORNER:
			resName = "Board_right_top_corner"
		GRID_TYPE.RIGHT_BOTTOM_CORNER:
			resName = "Board_right_bottom_corner"
		GRID_TYPE.TOP_CROSS:
			resName = "Board_top_cross"
		GRID_TYPE.BOTTOM_CROSS:
			resName = "Board_bottom_cross"
		GRID_TYPE.LEFT_CROSS:
			resName = "Board_left_cross"
		GRID_TYPE.RIGHT_CROSS:
			resName = "Board_right_cross"
	var resPath = "res://Assets/Images/" + resName + ".png"
	$Sprite.texture = load(resPath)



func _on_Area2D_input_event(viewport, event, shape_idx):
	if event.is_action_pressed("click"):
		if not get_tree().is_input_handled():
			emit_signal("on_grid_click", self.name)
			get_tree().set_input_as_handled()
	elif event is InputEventScreenTouch:
		if not get_tree().is_input_handled():
			emit_signal("on_grid_click", self.name)
			get_tree().set_input_as_handled()
		
